﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script src="../Static/jquery-1.6.2.min.js" type="text/javascript"></script>
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
    <script src="../Static/boot.js" type="text/javascript"></script>
    <link href="../Static/demo.css" rel="stylesheet" />
    <link href="../Static/miniui/themes/blue/skin.css" rel="stylesheet" />

    <style type="text/css">
        html, body {
            font-size: 12px;
            padding: 0;
            margin: 0;
            border: 0;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <div class="mini-toolbar">
        <span>帐号/姓名：</span>
        <input type="text" id="txtUserAccount" class="mini-textbox" style="width: 160px" />
        <span>区域：</span>
        <input id="category" class="mini-combobox" valuefield="ID" textfield="CategoryName" valuefromselect="true" onvaluechanged="selectChange"
               shownullitem="true" url="../Ajax/AjaxService.aspx?method=GetCategory" width="100" />

        <a class="mini-button" onclick="search()" iconcls="icon-search">查询</a>
        <a class="mini-button" onclick="clearWhere()" iconcls="icon-remove">清空条件</a>
    </div>
    <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a id="add" style="display: none" class="mini-button" iconcls="icon-add" onclick="addUser()" plain="true">增加</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-edit" onclick="DelUser()" plain="true">删除</a>
                    <span class="separator"></span>
                    <a class="mini-button" iconcls="icon-reload" onclick="searchPosiotn()" plain="true">刷新</a>
                </td>
            </tr>
        </table>
    </div>
    <div class="mini-fit" style="width: 100%; height: 100%;">
        <div id="grid" class="mini-datagrid" style="width: 100%; height: 100%;"
             showcolumnsmenu="true" url="../Ajax/AjaxService.aspx?method=GetUserCategoryMapping" idfield="id" multiselect="true"
             pagesize="20" sizelist="[10,15,20,50,100,200,300,500]" showcolumnsmenu="true">
            <div property="columns">
                <div type="checkcolumn" width="10">
                </div>
                <div type="indexcolumn" width="10">
                    序
                </div>

                <div field="username" headeralign="center" width="30">
                    帐号
                </div>
                <div field="realname" headeralign="center" width="50">
                    姓名
                </div>
                <div field="CategoryName" headeralign="center" width="50">
                    区域
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">

        mini.parse();
        var grid = mini.get("grid");
        grid.load();


        /**查询******************************************************************************/
        function search() {
            var userAccount = mini.get("txtUserAccount").getValue();
            var category = mini.get("category").getValue();
            grid.load({
                userAccount: userAccount,
                categoryid: category
            });
        }
        //-----------------------------清空条件-------------------------
        function clearWhere() {
            mini.get("txtUserAccount").setValue("");
            mini.get("category").setValue("");

        }
        $("#txtUserAccount").bind("keydown", function (e) {
            if (e.keyCode == 13) {
                search();
            }
        });
        $("#category").bind("keydown", function (e) {
            if (e.keyCode == 13) {
                search();
            }
        });
        function selectChange() {
            if (mini.get("category").getValue() == "") {
                document.getElementById("add").style.display = "none";
            } else {
                document.getElementById("add").style.display = "";
            }
            search();
        }
        
        /**给当前职位增加用户*********************************************************************/
        function addUser() {

            var categoryid = mini.get("category").getValue();
            if (categoryid == "") {
                alert("请选择区域！");
                return;
            }
            mini.open({
                url: "/AdminMana/Pub/SelectUser.html?",
                showMaxButton: false,
                title: "添加用户",
                width: 800,
                height: 500,
                onload: function () {
                    //打开子页面时传递参数
                    var iframe = this.getIFrameEl();
                    var data = { MultiSelect: "false" };
                    iframe.contentWindow.SetPara(data);
                },
                ondestroy: function (action) {
                    //返回数据时的操作
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);
                        if (data) {
                            // var userIDs = "";
                            var usersAccount = "";
                            for (var i = 0; i < data.length; i++) {

                                usersAccount = data[i].username + "," + usersAccount;
                            }
                            //增加
                            $.ajax({
                                url: "/AdminMana/Ajax/AjaxService.aspx?method=AddJCategoryUserMapping",
                                data: { usersAccount: usersAccount, categoryid: categoryid },
                                cache: false,
                                success: function (text) {

                                    var o = mini.decode(text);
                                    var message = o.res;
                                    if (o.error != "") {
                                        message += "\r\n" + "错误信息：" + o.error;
                                        mini.alert(message);
                                    }

                                    search();

                                },
                                error: function (jqXHR, textStatus, errorThrown) {
                                    mini.alert(jqXHR.responseText);
                                }
                            });
                        }

                    }
                    if (action == "clear") {

                    }

                }
            });

        }
        /**删除当前岗位用户*********************************************************************/
        function DelUser() {
            var rows = grid.getSelecteds();
            if (rows.length == 0) {
                alert("请先选中要删除项！");
                return;
            }
            
            var idArr = [];
            var accountArr = [];
            for (var i = 0, l = rows.length; i < l; i++) {
                var r = rows[i];
                idArr.push(r.ID);
                accountArr.push(r.username);
            }
            var ids = idArr.join(',');
            var accounts = accountArr.join(',');
            $.ajax({
                url: "/AdminMana/Ajax/AjaxService.aspx?method=DeleteJCategoryUserMapping",
                data: { ids: ids, accounts: accounts },
                cache: false,
                success: function (text) {

                    var o = mini.decode(text);
                    var message = o.res;
                    if (o.error != "") {
                        message += "\r\n" + "错误信息：" + o.error;
                        mini.alert(message);
                    }

                    search();

                },
                error: function (jqXHR, textStatus, errorThrown) {
                    mini.alert(jqXHR.responseText);
                }
            });
        }
    </script>
</body>
</html>
